﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class CategoryWise : System.Web.UI.Page
{
    protected int CId = 0;
    protected string AId = string.Empty;
    protected int PId = 0;
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Request.QueryString["CId"] != null)
        {
            CId = Convert.ToInt32(Request.QueryString["CId"]);
        }

        if (Request.QueryString["AId"] != null)
        {
            AId = Request.QueryString["AId"];
        }

        if (Request.QueryString["PId"] != null)
        {
            PId = Convert.ToInt32(Request.QueryString["PId"]);
        }

        if (CId > 0 || !string.IsNullOrEmpty(AId) || PId > 0)
        {
            List<EbookDetail> lstBooks = EbookDetail.GetAllEBooks();

            IEnumerable<EbookDetail> catBooks = lstBooks.AsEnumerable();

            if (CId > 0)
            {
                catBooks = (from book in catBooks
                            where book.CategoryId == CId
                            select book);
            }

            if (!string.IsNullOrEmpty(AId))
            {
                catBooks = (from book in catBooks
                            where book.Authors == AId
                            select book);
            }

            if (PId > 0)
            {
                catBooks = (from book in catBooks
                            where book.PublisherId == PId
                            select book);
            }

            if (catBooks != null && catBooks.Count() > 0)
            {
                eblCategoryBooks.DataSource = catBooks;
                eblCategoryBooks.DataBind();
                //EBookList1.ColumnCount = 1;
                ltCount.Text = catBooks.Count().ToString();
            }
        }
    }
}